package cn.seqdata.jpa.converter;

import java.sql.Timestamp;

import javax.persistence.AttributeConverter;

import org.joda.time.DateTime;

public class DateTimeConverter implements AttributeConverter<DateTime, Timestamp> {
	public static final DateTimeConverter instance = new DateTimeConverter();

	@Override
	public Timestamp convertToDatabaseColumn(DateTime attribute) {
		return null != attribute ? new Timestamp(attribute.getMillis()) : null;
	}

	@Override
	public DateTime convertToEntityAttribute(Timestamp dbData) {
		return null != dbData ? new DateTime(dbData.getTime()) : null;
	}
}
